Namespace ShapeLibrary
    <Designer(GetType(ShapeLibrary.Design.PolygonDesigner))> _
    Friend Class Polygon
        Inherits Shape

        Private m_color As Color = SystemColors.WindowText
        Private m_shapeFill As ShapeFill = ShapeFill.None
        Private m_fillColor As Color = SystemColors.WindowText
        Private m_bounds As Rectangle = Nothing
        Private m_fill As Boolean = False
        Private m_point1X As Single
        Private m_point2X As Single
        Private m_point3X As Single
        Private m_point4X As Single
        Private m_point1Y As Single
        Private m_point2Y As Single
        Private m_point3Y As Single
        Private m_point4Y As Single
        Private m_points As PointF() = Nothing
        Private m_fillbrush As SolidBrush = New SolidBrush(m_fillColor)

        '''
        ''' The bounds of the ellipse, in pixels.
        '''
        <Description("Fill Polygon?")> _
        Public Property FillPolygon() As Boolean
            Get
                Return m_fill
            End Get

            Set(ByVal Value As Boolean)
                m_fill = Value
            End Set
        End Property
        <Description("Points 1 of the polygon in pixels.")> _
        Public Property Point1X() As Single
            Get
                Return m_point1X
            End Get

            Set(ByVal Value As Single)
                m_point1X = Value
            End Set
        End Property
        Public Property Point1Y() As Single
            Get
                Return m_point1Y
            End Get

            Set(ByVal Value As Single)
                m_point1Y = Value
            End Set
        End Property
        '''
        ''' The bounds of the ellipse, in pixels.
        '''
        <Description("Points 2 of the polygon in pixels.")> _
        Public Property Point2X() As Single
            Get
                Return m_point2X
            End Get

            Set(ByVal Value As Single)
                m_point2X = Value
            End Set
        End Property
        Public Property Point2Y() As Single
            Get
                Return m_point2Y
            End Get

            Set(ByVal Value As Single)
                m_point2Y = Value
            End Set
        End Property
        '''
        ''' The bounds of the ellipse, in pixels.
        '''
        <Description("Points 3 of the polygon in pixels.")> _
        Public Property Point3X() As Single
            Get
                Return m_point3X
            End Get

            Set(ByVal Value As Single)
                m_point3X = Value
            End Set
        End Property
        Public Property Point3Y() As Single
            Get
                Return m_point3Y
            End Get

            Set(ByVal Value As Single)
                m_point3Y = Value
            End Set
        End Property
        '''
        ''' The bounds of the ellipse, in pixels.
        '''
        <Description("Points 4 of the polygon in pixels.")> _
        Public Property Point4X() As Single
            Get
                Return m_point4X
            End Get

            Set(ByVal Value As Single)
                m_point4X = Value
            End Set
        End Property
        Public Property Point4y() As Single
            Get
                Return m_point4Y
            End Get

            Set(ByVal Value As Single)
                m_point4Y = Value
            End Set
        End Property
        Public Property Points() As PointF()
            Get
                Return m_points
            End Get
            Set(ByVal value As PointF())
                m_points = value
            End Set
        End Property

        '''
        ''' The bounds of the ellipse, in pixels.
        '''
        <Description("The bounds of the ellipse in pixels.")> _
        Public Property Bounds() As Rectangle
            Get
                Return m_bounds
            End Get

            Set(ByVal Value As Rectangle)
                m_bounds = Value
            End Set
        End Property

        '''
        ''' The color of the ellipse.
        '''
        <Description("The color of the ellipse.")> _
        Public Property Color() As Color
            Get
                Return m_color
            End Get

            Set(ByVal Value As Color)
                m_color = Value
            End Set
        End Property
        <Description("The Fill color of the ellipse.")> _
        Public Property FillColor() As Color
            Get
                Return m_fillColor
            End Get

            Set(ByVal Value As Color)
                m_fillColor = Value
                m_fillbrush = New SolidBrush(m_fillColor)
            End Set
        End Property

        '''
        ''' A fill style for the ellipse.
        '''
        <Description("The pattern and color to fill the ellipse."), _
        DefaultValue(GetType(ShapeFill), "None")> _
        Public Property Fill() As ShapeFill
            Get
                Return m_shapeFill
            End Get
            Set(ByVal Value As ShapeFill)
                m_shapeFill = Value
            End Set
        End Property

        '''
        ''' Overrides Shape.Draw
        '''
        Friend Overrides Sub Draw(ByVal g As Graphics)
            Dim p As Pen = New Pen(Color)
            Dim polygonPoints As PointF()
            If IsNothing(m_points) Then
                Dim tmp As PointF() = { _
                    New PointF(m_point1X + m_bounds.Left, m_point1Y + m_bounds.Top), _
                    New PointF(m_point2X + m_bounds.Left, m_point2Y + m_bounds.Top), _
                    New PointF(m_point3X + m_bounds.Left, m_point3Y + m_bounds.Top), _
                    New PointF(m_point4X + m_bounds.Left, m_point4Y + m_bounds.Top) _
                }
                polygonPoints = tmp
            Else
                Dim tmp As PointF() = m_points
                polygonPoints = tmp
            End If

            Try
                g.DrawPolygon(p, polygonPoints)
                g.SmoothingMode = SmoothingMode.AntiAlias
                If m_fill Then
                    g.FillPolygon(m_fillbrush, polygonPoints)
                End If
                'If Not (m_shapeFill Is Nothing) AndAlso Not (m_shapeFill.Brush Is Nothing) Then
                'g.FillEllipse(m_Fillcolor, Bounds)
                '' g.FillPolygon(m_shapeFill.Brush, polygonPoints)
                'End If
            Finally

            End Try
        End Sub
    End Class
End Namespace
